# Maintainer: David Runge <dvzrv@archlinux.org>

_name=tzinfo
pkgname=ruby-tzinfo
pkgver=2.0.5
pkgrel=1
pkgdesc='Daylight savings aware transformations between times in different time zones'
arch=(any)
url="https://github.com/tzinfo/tzinfo"
license=(MIT)
depends=(ruby ruby-concurrent)
makedepends=(ruby-rake ruby-rdoc)
# TODO: package ruby-simplecov
# checkdepends=(ruby-minitest ruby-simplecov)
options=(!emptydirs)
source=($pkgname-$pkgver.tar.gz::https://github.com/$_name/$_name/archive/v$pkgver.tar.gz)
sha512sums=('a3c59b1f390b186356b9219b0fb18bb762d2123936553738e1068ba46bf0206c5a0394b1d46b5c7b891aa55b8afa839858837511f53e3ef0eb0e85fe3f23b57a')
b2sums=('44e6d65dadc4828e4b8803c0badf381e18afe7412e090c4d91147b144f300a8c0e3189bc8e8325625678a57ea6a1179a1ed277f5fb54230ce77c46ba6b0100c7')

prepare() {
  cd "$_name-$pkgver"
  # we do not do version pinning
  sed --regexp-extended 's,~>,>=,g' --in-place *.gemspec Gemfile Rakefile
  # lockfiles should be removed
  rm -fv Gemfile.lock
  # do not rely on Gemfiles (unless the project *really* needs it)
  rm -fv Gemfile
}

build() {
  cd $_name-$pkgver
  gem build $_name.gemspec
}

# check(){
#   cd $_name-$pkgver
#   rake test
# }

package() {
  local _gemdir="$(gem env gemdir)"

  cd $_name-$pkgver
  gem install \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_name-$pkgver.gem"

  # remove unrepreducible files
  rm -frv \
    "$pkgdir/$_gemdir/cache/" \
    "$pkgdir/$_gemdir/gems/$_name-$pkgver/vendor/" \
    "$pkgdir/$_gemdir/doc/$_name-$pkgver/ri/ext/"

  find "$pkgdir/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete

  find "$pkgdir/$_gemdir/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
